package com.cssnj.portal.service.user;

import io.predictech.framework.domain.common.JsonRequest;
import io.predictech.framework.domain.common.JsonResponse;
import io.predictech.framework.domain.exception.BaseException;
import io.predictech.framework.service.base.BaseService;
import io.predictech.framework.utility.PredictechUtil;
import io.predictech.framework.utility.StringUtil;
import org.springframework.stereotype.Service;

import java.sql.SQLException;

@Service("permissionService")
public class PermissionService extends BaseService {


    @Override
    protected JsonResponse invokingService(JsonRequest jsonRequest) throws SQLException, BaseException {
        return null;
    }


    /**
     * 是否管理员专有URL
     *
     * @param requestURI
     * @return boolean
     */
    public boolean isAdminUrl(String requestURI) {
        return requestURI.contains("/admin/");
    }


    /**
     * 是否需要权限过滤
     *
     * @param requestURI
     * @return boolean
     */
    public boolean needInterceptor(String requestURI) {
        return PredictechUtil
                .getCodeData("GL_GN")
                .parallelStream()
                .anyMatch(permissionMap -> requestURI.equals(StringUtil.empty(permissionMap.get("HREF"))) && "1".equals(permissionMap.get("KZ_BJ")));
    }
}
